home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / lh113src.zip / SFX2.ASM < prev    next >
Assembly Source File  |  1989-05-04  |  25KB  |  1,255 lines

  1. page    66, 120                    ;
  2. ;$_init                        ;
  3. ;***********************************************;
  4. ;       LHarc version 1.13 (c) Yoshi 1988-89.    ;
  5. ;       self-extract module : 1989/ 5/ 4    ;
  6. ;                        ;
  7. ; HTAB = 8                    ;
  8. ;***********************************************;
  9.                         ;
  10. _TEXT    segment    byte public 'CODE'        ;
  11. _TEXT    ends                    ;
  12.                         ;
  13. DGROUP    group    _BSS                ;
  14.     assume    cs:_TEXT, ds:DGROUP        ;
  15.                         ;
  16.         public    THRESHOLD, F, N_CHAR, T    ;
  17. THRESHOLD    equ    2            ;
  18. F        equ    60            ;
  19. N_CHAR        equ    (256 - THRESHOLD + F)    ;
  20. T        equ    (N_CHAR * 2 - 1)    ;
  21. R        equ    (T - 1)            ;
  22. N        equ    1000h            ;
  23. MAX_FREQ    equ    8000h            ;
  24. CRC16        equ    0a001h            ;
  25. BufSiz        equ    04000h            ;
  26.                         ;
  27. LzHead    struc                    ;
  28.     HeadSiz    db    ?            ;
  29.     HeadChk    db    ?            ;
  30.     HeadID    db    3 dup (?)        ;
  31.     Method    db    ?            ;
  32.         db    ?            ;
  33.     PacSiz    dw    2 dup (?)        ;
  34.     OrgSiz    dw    2 dup (?)        ;
  35.     FTime    dw    ?            ;
  36.     FDate    dw    ?            ;
  37.     FAttr    dw    ?            ;
  38.     FnLen    db    ?            ;
  39.     Fname    db    80h dup (?)        ;
  40. LzHead    ends                    ;
  41.                         ;
  42. _BSS    segment    para public 'BSS'        ;
  43.     public    freq, prnt, son            ;
  44.     public    d_len, d_code            ;
  45.     public    crctbl                ;
  46.     public    cpyhdr, infile, outfile        ;
  47.     public    inpptr                ;
  48.     public    curcrc, iobuf, iolen, crcflg, orgcrc
  49.     public    myname, keyword, keyword2, keycnt
  50.     public    param, pathname, fnnext, swchar    ;
  51.                         ;
  52. freq        dw    (T + 1) dup (?)        ;
  53. prnt        dw    (T + N_CHAR) dup (?)    ;
  54. son        dw    T dup (?)        ;
  55. d_len        db    100h dup (?)        ;
  56. d_code        db    100h dup (?)        ;
  57. crctbl        dw    100h dup (?)        ;
  58. text_buf    db    N dup (?)        ;
  59. inpbuf        db    BufSiz dup (?)        ;
  60. inpptr        dw    1 dup (?)        ;
  61. cpyhdr        LzHead    1 dup (<?>)        ;
  62. infile        dw    1 dup (?)        ;
  63. outfile        dw    1 dup (?)        ;
  64. orgcrc        dw    1 dup (?)        ;
  65. curcrc        dw    1 dup (?)        ;
  66. iobuf        dw    1 dup (?)        ;
  67. crcflg        db    1 dup (?)        ;
  68. iolen        db    1 dup (?)        ;
  69. myname        db    80h dup (?)        ;
  70. keyword        db    80h dup (?)        ;
  71. keyword2    db    80h dup (?)        ;
  72. param        dw    20 dup (?)        ;
  73. pathname    db    80h dup (?)        ;
  74. fnnext        dw    1 dup (?)        ;
  75. fnptr        dw    1 dup (?)        ;
  76. swchar        db    1 dup (?)        ;
  77. endBBS        label    byte            ;
  78. _BSS        ends                ;
  79.                         ;
  80. _TEXT    segment    byte public 'CODE'        ;
  81.     assume    cs:_TEXT            ;
  82.                         ;
  83.     org    0100h                ;
  84.                         ;
  85.     public    start, main            ;
  86.     public    BSSseg                ;
  87.     public    cright, chglen, crlf, space    ;
  88.     public    absent, myself, broken, extend    ;
  89. start:                        ;
  90.     jmp    main                ;
  91.                         ;
  92. BSSseg    =    (endofcode - start + 10fh) / 10h;
  93. mes_yn    equ    space - 1            ;
  94. space    db    ' ', 0                ;
  95. cright    db    "LHarc's SFX 1.13L (c)Yoshi, 1989."
  96.     db    13, 10, 10, 0            ;
  97. absent    db    'Rename to '            ;
  98. myself    db    '            ', 0        ;
  99. chglen    db    01h, 04h, 0ch, 18h, 30h        ; next byte must not be 3?h
  100. overwt    db    'Overwrite ', 0            ;
  101. yesno    db    '[Y/N] ', 0            ;
  102. broken    db    'Broken file ', 0        ;
  103. write    db    'Write', 0            ;
  104. header    db    'Header', 0            ;
  105. crcmes    db    'CRC'                ;
  106. error    db    ' Error'            ;
  107. crlf    db    13, 10, 0            ;
  108. auto    db    8, 'AUTOLARC'            ;
  109. autoflg    db    '.'                ;
  110.     db    'BAT'                ;
  111. extend    db    0                ;
  112. attrib    db    0                ;
  113. keycnt    dw    0                ;
  114.                         ;
  115. envseg    =    002ch                ;
  116. cmdcnt    =    0080h                ;
  117. cmdline    =    0081h                ;
  118.                         ;
  119. ;-----------------------------------------------;
  120. ;    âüâCâôâïü[â`âô                ;
  121. ;-----------------------------------------------;
  122. main:                        ;
  123.     cld                    ;
  124.     mov    sp, offset start        ;
  125.     mov    bx, offset cright        ;
  126.     call    mesout                ;
  127.     mov    ax, cs                ;
  128.     add    ax, BSSseg            ;
  129.     mov    es, ax                ;
  130.                         ;
  131.     assume    es:DGROUP            ;
  132. ;-----------------------------------------------;
  133. ;    Get options                ;
  134. ;-----------------------------------------------;
  135.     public    getopt                ;
  136. getopt:                        ;
  137.     mov    ax, 3700h            ;
  138.     int    21h                ; get switch char
  139.     mov    si, cmdline            ;
  140.     mov    es:swchar, dl            ;
  141.                         ;
  142.     mov    es:fnnext, offset DGROUP:pathname
  143. $_1:
  144.         lodsb                ;
  145.         call isspace
  146.         jE $_3
  147.         cmp al, es:swchar
  148.         jE $_4
  149.         cmp al, '-'
  150.         jNE $_5
  151. $_4:
  152. lp0:                        ;
  153.             lodsb            ;
  154.             call isspace
  155.             jE $_6
  156.             cmp al, 'e'
  157.             jNE $_8
  158.                 lodsb        ;
  159.                 mov        di, offset DGROUP:pathname
  160.                 mov        ah, '\'    ;
  161.                 call    trans_t    ;
  162.                 mov        al, ah    ;
  163.                 call isdelim2
  164.                 jE $_9
  165.                 mov    al, '\'    ;
  166.                 stosb        ;
  167. $_9:
  168.                 mov        es:fnnext, di
  169.                 dec        si        ;
  170.                 jmp short $_7
  171. $_8:
  172.             cmp al, 'x'
  173.             jNE $_10
  174.                 inc        cs:extend    ;
  175.                 jmp short $_7
  176. $_10:
  177.             cmp al, 'a'
  178.             jNE $_11
  179.                 inc        cs:attrib    ;
  180. $_11:
  181. $_7:
  182.             jmp    lp0        ;
  183. $_6:
  184.         jmp short $_12
  185. $_5:
  186.             mov        di, offset DGROUP:keyword
  187.             mov        dx, di        ;
  188.             call    trans        ;
  189.             sub        di, dx        ;
  190.             mov        cs:keycnt, di    ;
  191. $_12:
  192. lp1:                        ;
  193. $_3:
  194.     cmp al, 0dh
  195.     jNE $_1
  196. $_2:
  197.                         ;
  198. public    mnlp1                    ;
  199. mnlp1:                        ;
  200.     push    es                ;
  201.     pop    ds                ;
  202.                         ;
  203.     assume    ds:DGROUP            ;
  204. ;-----------------------------------------------;
  205. ;    Get my name                ;
  206. ;-----------------------------------------------;
  207.     mov    ah, 30h                ;
  208.     int    21h                ; get DOS ver.
  209.     push    ds                ;
  210.     cmp al, 3
  211.     jB $_13
  212.         mov    ax, cs:[envseg]        ;
  213.         mov    es, ax            ;
  214.         xor    ax, ax            ;
  215.         mov    di, ax            ;
  216.         mov    cx, -1            ;
  217. $_14:
  218.             repne    scasb        ;
  219.             scasb            ;
  220.         jNE $_14
  221. $_15:
  222.         inc    ax            ;
  223.         scasw                ;
  224.         push    es            ;
  225.         pop    ds            ;
  226.         mov    dx, di            ;
  227.         je    openme            ;
  228.     jmp short $_16
  229. $_13:
  230.         mov    ax, cs:[0002h]        ;
  231.         sub    ax, 38h            ;
  232.         mov    ds, ax            ;
  233.         mov    dx, 0009h        ;
  234.         jmp    short openme        ;
  235. $_16:
  236. brknenv:                    ;
  237.     push    cs                ;
  238.     pop    ds                ;
  239.     mov    dx, offset myself        ;
  240. openme:                        ;
  241.     mov    ax, 3d00h            ;
  242.     int    21h                ; Open Myself
  243.     jNC $_17
  244.         cmp    dx, offset myself    ;
  245.         jne    brknenv            ;
  246.         mov    bx, offset absent    ;
  247.         call    mesout            ;
  248.         mov    bx, offset crlf        ;
  249.         jmp    errout1            ;
  250. $_17:
  251.     pop    ds                ;
  252.     mov    infile, ax            ;
  253.                         ;
  254.     mov    bx, ax                ;
  255.     xor    cx, cx                ;
  256. exehdr    =    20h                ;
  257.     mov    dx, (endofcode - start) + exehdr;
  258.     mov    ax, 4200h            ;
  259.     int    21h                ; Move a File Pointer
  260.     jNC $_18
  261.         mov    bx, offset broken    ; Broken file
  262.         jmp    errout            ;
  263. $_18:
  264.     push    ds                ;
  265.     pop    es                ;
  266. ;-----------------------------------------------;
  267. ;    Get Key-word from SFX-file        ;
  268. ;-----------------------------------------------;
  269.     mov    di, offset DGROUP:keyword2    ;
  270.     lea    dx, [di + 79]            ;
  271.     mov    si, dx                ;
  272.     mov    cx, 1                ;
  273.     mov    bx, infile            ;
  274. $_19:
  275.         mov    [si], ch        ; for error detect (ch = 0)
  276.         mov    ah, 3fh            ;
  277.         int    21h            ; Read 1 char
  278.         mov    al, [si]        ;
  279.         stosb                ;
  280.     or al,al
  281.     jNZ $_19
  282. $_20:
  283. ;---------------------------------------    ;
  284. ;    make CRC table                ;
  285. ;---------------------------------------    ;
  286.     mov    di, offset crctbl        ;
  287.     xor    dx, dx                ;
  288. $_21:
  289.         mov    ax, dx            ;
  290.         mov    cx, 8            ;
  291. $_23:
  292.             shr ax, 1
  293.             jNC $_25
  294.                 xor    ax, CRC16
  295. $_25:
  296.         LOOP $_23
  297. $_24:
  298.         stosw                ;
  299.     inc dl
  300.     jNZ $_21
  301. $_22:
  302. ;---------------------------------------    ;
  303. ; make table for position            ;
  304. ;---------------------------------------    ;
  305.     mov    si, offset _TEXT:chglen        ;
  306.     mov    di, offset DGROUP:d_len        ;
  307.     mov    ax, 1                ; d_len = real length - 2
  308.     mov    dx, 0020h            ;
  309. $_26:
  310.         cmp ah, cs:[si]
  311.         jNE $_28
  312.             inc    al        ;
  313.             inc    si        ;
  314.             shr    dx, 1        ;
  315. $_28:
  316.         mov    cx, dx            ;
  317. $_29:
  318.             mov    [di + d_code - d_len], ah
  319.             stosb            ;
  320.         LOOP $_29
  321. $_30:
  322.         inc    ah            ;
  323.     cmp ah, 040h
  324.     jL $_26
  325. $_27:
  326. ;---------------------------------------    ;
  327.                         ;
  328.     public mainloop                ;
  329. mainloop:                    ;
  330. $_31:
  331.                         ;
  332. ; Get Header ---------------------------    ;
  333.         mov    DGROUP:cpyhdr.HeadSiz, 0;
  334.         mov    bx, infile        ;
  335.         mov    cx, 1            ;
  336.         mov    dx, offset DGROUP:cpyhdr.HeadSiz
  337.         mov    ah, 3fh            ;
  338.         int    21h            ; Read header size
  339.         dec    cx            ; cx = 0
  340.         add    cl, DGROUP:cpyhdr.HeadSiz
  341.         jNZ $_34
  342.             jmp    exit        ;
  343. $_34:
  344.         inc    dx            ;
  345.         mov    si, dx            ;
  346.                         ;
  347.         inc    cx            ;
  348.         mov    ah, 3fh            ;
  349.         int    21h            ; Read header
  350.                         ;
  351. ; Test Header Sum ----------------------    ;
  352.         lodsb                ;
  353.         mov    di, si            ; cpyhdr.HeadID
  354.         dec    cx            ;
  355. $_35:
  356.             sub    al, [si]    ;
  357.             inc    si        ;
  358.         LOOP $_35
  359. $_36:
  360.         or    al, al            ;
  361.         jne    errhdr            ;
  362.         xchg    di, si            ; di = end of cpyhdr
  363.                         ;
  364. ; Test Header ID -----------------------    ;
  365.         lodsw                ;
  366.         cmp    ax, 'l-'        ;
  367.         jne    errhdr            ;
  368.         lodsw                ;
  369.         xchg    al, ah            ;
  370.         sub    ax, 'h0'        ;
  371.         mov    bp, ax            ; bp = method
  372.         cmp    ax, 0001h        ;
  373.         ja    errhdr            ;
  374.         lodsb                ;
  375.         cmp    al, '-'            ;
  376.         jE $_37
  377. errhdr:                        ;
  378.             mov    bx, offset header
  379.             jmp    errout        ;
  380. $_37:
  381.                         ;
  382. ; Get original CRC ---------------------    ;
  383.         mov    bx, offset DGROUP:cpyhdr.Fname
  384.         mov    dx, bx            ;
  385.         mov    cl, [bx - 1]        ; ch = 0
  386.         add    bx, cx            ;
  387.                         ;
  388.         mov    ax, [bx]        ; may be CRC
  389.         mov    orgcrc, ax        ;
  390.                         ;
  391.         sub    di, bx            ; bx  = end of Fname
  392.         mov    word ptr crcflg, di    ; if 2, crc supported.
  393.                         ; iolen = 0 also.
  394.                         ;
  395. ; Test Special File ? ------------------    ;
  396.         mov    ax, 1            ;
  397.         mov    fnptr, dx        ;
  398.         cmp    word ptr DGROUP:cpyhdr.FnLen, 2101h ; 01h, '!'
  399.         jNE $_38
  400.             jmp    mn7        ;
  401. $_38:
  402.                         ;
  403.         mov    si, dx            ;
  404.         mov    di, offset auto + 1    ; AUTOLARC.BAT ?
  405.         mov    cl, 12            ; ch may be 0
  406.         push    es            ;
  407.         push    cs            ;
  408.         pop    es            ;
  409.         rep    cmpsb            ;
  410.         pop    es            ;
  411.         je    mn2            ;
  412.                         ;
  413. ; -x switch ----------------------------    ;
  414.         mov    si, dx            ;
  415.         cmp cs:extend, 0
  416.         jNE $_39
  417. $_40:
  418.                 lodsb        ;
  419.                 call isdelim2
  420.                 jNE $_43
  421.                     mov    dx, si
  422.                     jmp short $_42
  423. $_43:
  424.                 call iskanji
  425.                 jNE $_44
  426.                     inc    si
  427. $_44:
  428. $_42:
  429.             cmp si, bx
  430.             jB $_40
  431. $_41:
  432.             mov    si, dx        ;
  433. $_39:
  434.                         ;
  435. ; -eDIRECTORY --------------------------    ;
  436.         mov    al, [si]        ;
  437.         call isdelim2
  438.         jE $_45
  439.             mov    cx, bx        ;
  440.             sub    cx, dx        ;
  441.             mov    dx, offset DGROUP:pathname
  442.             mov    di, fnnext    ;
  443.             rep    movsb        ;
  444.             mov    bx, di        ;
  445.         jmp short $_46
  446. $_45:
  447.             mov    ax, word ptr DGROUP:pathname
  448.             cmp ah, ':'
  449.             jNE $_47
  450.                 dec    dx    ;
  451.                 dec    dx    ;
  452.                 mov    di, dx    ;
  453.                 mov    [di], ax; brakes FnLen and
  454. $_47:
  455. $_46:
  456.         mov    fnptr, dx        ;
  457.         mov    cx, 1            ;
  458.                         ;
  459. ; Display File name --------------------    ;
  460. mn2:                        ;
  461.         mov    word ptr [bx], 0 * 256 + ' '
  462.         mov    bx, dx            ;
  463.         push    dx            ;
  464.         call    dispent            ; output file name
  465.         pop    dx            ;
  466.         mov    byte ptr [bx - 1], 0    ;
  467.                         ;
  468.         jcxz    mn9            ; AUTOLARC.BAT ?
  469.                         ;
  470. ; Check Existence of File --------------    ;
  471.         mov    ax, 4300h        ; get file attr
  472.         int    21h            ;   (for MS-DOS 3.3)
  473.         jc    mn5            ;
  474.                         ;
  475.         mov    bx, offset overwt    ; prompt
  476.         call    mesout            ;
  477.         call    getyn            ;
  478.         je    mn1            ;
  479.                         ;
  480. ; Skip to next File --------------------    ;
  481.         mov    dx, DGROUP:cpyhdr.PacSiz    ; skip file
  482.         mov    cx, DGROUP:cpyhdr.PacSiz + 2
  483.                         ;
  484.         mov    bx, infile        ;
  485.         mov    ax, 4201h        ;
  486.         int    21h            ; Move a File Pointer
  487.         jmp    mn6            ;
  488. mn9:                        ;
  489.         mov    cs:autoflg, 0dh        ;
  490.                         ;
  491. ; Make Directories ---------------------    ;
  492. mn5:                        ;
  493.         mov    si, dx            ;
  494.         lodsb                ;
  495.         jmp    short mn0        ;
  496. $_48:
  497.             lodsb            ;
  498.             call isdelim2
  499.             jNE $_50
  500.                 mov    byte ptr [si - 1], 0
  501.                 mov    ah, 39h    ; make dir
  502.                 int    21h    ;
  503.                 mov    byte ptr [si - 1], '\'
  504. $_50:
  505. mn0:                        ;
  506.             call iskanji
  507.             jNE $_51
  508.                 inc    si    ;
  509. $_51:
  510.         cmp al, 0
  511.         jNE $_48
  512. $_49:
  513.                         ;
  514. ; Create a New File --------------------    ;
  515. mn1:                        ;
  516.         mov    cl, 20h            ; ch may be 0
  517.         mov    ah, 3ch            ;
  518.         int    21h            ; Create a File
  519.         jNC $_52
  520.             jmp    errwrite    ;
  521. $_52:
  522.                         ;
  523. ; Decode -------------------------------    ;
  524. mn7:                        ;
  525.         mov    outfile, ax        ;
  526.                         ;
  527.         mov    curcrc, 0        ;
  528. ;        mov    iolen, 0        ; already iolen = 0
  529.         mov    inpptr, -1        ;
  530.                         ;
  531.         push    dx            ;
  532.         or bp, bp
  533.         jZ $_53
  534.             call    Decode        ;
  535.         jmp short $_54
  536. $_53:
  537.             call    copyall        ;
  538. $_54:
  539.         pop    si            ;
  540.                         ;
  541. ; Set Time-Stamp -----------------------    ;
  542.         mov    bx, outfile        ;
  543.         cmp    bx, 1            ; file '!' ?
  544.         je    mn8            ;
  545.                         ;
  546.         mov    dx, DGROUP:cpyhdr.FDate    ;
  547.         mov    cx, DGROUP:cpyhdr.FTime    ;
  548.         mov    ax, 5701h        ; set date
  549.         int    21h            ;
  550.         mov    bx, outfile        ;
  551.         call    close            ;
  552.                         ;
  553. ; Check CRC ----------------------------    ;
  554.         mov    dx, si            ;
  555.         cmp crcflg, 2
  556.         jNE $_55
  557.             mov    ax, curcrc    ;
  558.             cmp    ax, orgcrc    ;
  559.             jne    errcrc        ;
  560. $_55:
  561.                         ;
  562. ; Set File Attributes ------------------    ;
  563.         cmp attrib, 0
  564.         jE $_56
  565.             mov    cl, byte ptr DGROUP:cpyhdr.FAttr
  566.             mov    ch, 0        ;
  567.             mov    ax, 4301h    ;
  568.             int    21h        ; Set File Attributes
  569. $_56:
  570.         jmp    mn6            ;
  571. mn8:                        ;
  572.         call    getyn            ;
  573.         jne    exit1            ;
  574. mn6:                        ;
  575.         mov    bx, offset crlf        ;
  576.         call    mesout            ;
  577.     jmp $_31
  578. $_33:
  579. $_32:
  580.     public    exit                ;
  581. exit:                        ;
  582.     push    ds                ;
  583.     pop    es                ;
  584.     cmp cs:autoflg, 0dh
  585.     jNE $_57
  586.         mov    cx, keycnt        ;
  587.         jcxz    exit1            ;
  588.         inc    cx            ;
  589.         mov    si, offset DGROUP:keyword
  590.         mov    di, offset DGROUP:keyword2
  591.     repe cmpsb
  592.     jNE $_57
  593.         push    cs            ;
  594.         pop    es            ;
  595.         mov    bx, (offset resident - start + 100h + 15) / 16
  596.         mov    ah, 4ah            ;
  597.         int    21h            ;
  598.         push    cs            ;
  599.         pop    ds            ;
  600.         mov    si, offset auto        ;
  601.         int    2eh            ; execute
  602. $_57:
  603. exit1:                        ;
  604.     mov    ax, 4c00h            ;
  605.     int    21h                ;
  606. resident:                    ;
  607.                         ;
  608. ;-----------------------------------------------;
  609. ;    âGâëü[Åêù¥                ;
  610. ;-----------------------------------------------;
  611.     public    errhdr, errwrite, errout    ;
  612. errcrc:                        ;
  613.     call    unlink                ;
  614.     mov    bx, offset crcmes        ;
  615.     jmp    short errout1            ;
  616.                         ;
  617. errwrite:                    ;
  618.     mov    bx, outfile            ;
  619.     call    close                ;
  620.     call    unlink                ;
  621.     mov    bx, offset write        ;
  622.                         ;
  623. errout:                        ;
  624.     call    mesout                ;
  625.     mov    bx, offset error        ;
  626. errout1:                    ;
  627.     call    mesout                ;
  628.     mov    bx, infile            ;
  629.     call    close                ;
  630.     mov    ax, 4c01h            ;
  631.     int    21h                ;
  632.                         ;
  633. ;-----------------------------------------------;
  634. ;    get 'Y' or 'N'                ;
  635. ;-----------------------------------------------;
  636.     public    getyn                ;
  637. getyn    proc    near                ;
  638.     mov    bx, offset yesno        ; prompt
  639.     call    mesout                ;
  640. $_58:
  641.         mov    ah, 08h            ;
  642.         int    21h            ;
  643.         and    al, 0dfh        ;
  644.     cmp al, 'Y'
  645.     jE $_60
  646.     cmp al, 'N'
  647.     jNE $_58
  648. $_59:
  649. $_60:
  650.     mov    bx, offset mes_yn        ;
  651.     mov    cs:[bx], al            ;
  652.     call    mesout                ;
  653.     cmp    al, 'Y'                ;
  654.     ret                    ;
  655. getyn    endp                    ;
  656. ;-----------------------------------------------;
  657. ;    âoâbâtâ@é╠Åoù═                ;
  658. ;-----------------------------------------------;
  659.     public    putbuf                ;
  660. putbuf    proc    near                ;
  661.     mov    dx, offset text_buf        ;
  662.     mov    cx, di                ;
  663.     mov    bx, outfile            ;
  664.     mov    ah, 40h                ; write to file
  665.     int    21h                ;
  666.     jc    errwrite            ;
  667.     sub ax, cx
  668.     jE $_61
  669.         cmp    bx, 1            ;
  670.         jne    errwrite        ;
  671. $_61:
  672.                         ;
  673.     push    si                ;
  674.     mov    si, dx                ;
  675.     jcxz    putbuf9                ;
  676.     mov    ax, curcrc            ;
  677. $_62:
  678.         xor    al, [si]        ;
  679.         inc    si            ;
  680.         mov    bl, al            ; crc & 0xff
  681.         xor    bh, bh            ;
  682.         mov    al, ah            ; crc >> 8
  683.         xor    ah, ah            ;
  684.         shl    bx, 1            ;
  685.         xor    ax, crctbl[bx]        ;
  686.     LOOP $_62
  687. $_63:
  688.     mov    curcrc, ax            ;
  689. putbuf9:                    ;
  690.     pop    si                ;
  691.     cmp    outfile, 1            ;
  692.     je    return                ;
  693.     mov    ah, 02h                ;
  694.     mov    dl, '.'                ;
  695.     jmp    short int21_ret            ; int    21h
  696.                         ; ret
  697. putbuf    endp                    ;
  698.                         ;
  699. ;-----------------------------------------------;
  700. ;    é╗é╠é▄é▄Åoù═                ;
  701. ;-----------------------------------------------;
  702.     public    copyall                ;
  703. copyall    proc    near                ;
  704.     xor    di, di                ;
  705. $_64:
  706.         mov    bx, offset DGROUP:cpyhdr.OrgSiz
  707.         sub    [bx], di        ;
  708.         sbb    word ptr 2[bx], 0    ;
  709.         mov    cx, N            ;
  710.         jNE $_67
  711.             mov    ax, [bx]    ;
  712.             or    ax, ax        ;
  713.             jz    cpyend        ;
  714.         cmp ax, cx
  715.         jAE $_67
  716.             mov    cx, ax        ;
  717. $_67:
  718.                         ;
  719.         mov    dx, offset DGROUP:text_buf
  720.         mov    bx, infile        ;
  721.         mov    ah, 3fh            ;
  722.         int    21h            ;
  723.         mov    di, cx            ;
  724.         call    putbuf            ;
  725.     jmp $_64
  726. $_66:
  727. $_65:
  728. cpyend:                        ;
  729.     ret                    ;
  730. copyall    endp                    ;
  731.                         ;
  732. ;-----------------------------------------------;
  733. ;    âtâ@âCâïé╠ close            ;
  734. ;-----------------------------------------------;
  735.     public    close                ;
  736. close    proc    near                ;
  737.     mov    ah, 3eh                ;
  738.     jmp    short int21_ret            ; int    21h
  739.                         ; ret
  740. close    endp                    ;
  741.                         ;
  742. ;-----------------------------------------------;
  743. ;    âtâ@âCâïé╠ìφÅ£                ;
  744. ;-----------------------------------------------;
  745.     public    unlink                ;
  746. unlink    proc    near                ;
  747.     mov    dx, fnptr            ;
  748.     mov    ah, 41h                ; unlink
  749. int21_ret:                    ;
  750.     int    21h                ;
  751. return:                        ;
  752.     ret                    ;
  753. unlink    endp                    ;
  754.                         ;
  755. ;-----------------------------------------------;
  756. ;    buffer ôⁿù═                ;
  757. ;-----------------------------------------------;
  758.     public    getbuf                ;
  759. getbuf    proc    near                ;
  760.     push    ax                ;
  761.     push    bx                ;
  762.     push    cx                ;
  763.     push    dx                ;
  764.     mov    bx, infile            ;
  765.     mov    dx, offset DGROUP:inpbuf    ;
  766.     mov    cx, BufSiz            ;
  767.     cmp DGROUP:cpyhdr.PacSiz + 2, 0
  768.     jNE $_68
  769.     cmp cx, DGROUP:cpyhdr.PacSiz
  770.     jBE $_68
  771.         mov    cx, DGROUP:cpyhdr.PacSiz;
  772. $_68:
  773.     sub    DGROUP:cpyhdr.PacSiz, cx    ;
  774.     sbb    DGROUP:cpyhdr.PacSiz + 2, 0    ;
  775.     mov    ah, 3fh                ;
  776.     int    21h                ; Read from an Archive
  777.     mov    inpptr, dx            ;
  778.     pop    dx                ;
  779.     pop    cx                ;
  780.     pop    bx                ;
  781.     pop    ax                ;
  782.     ret                    ;
  783. getbuf    endp                    ;
  784.                         ;
  785. ;-----------------------------------------------;
  786. ;    âüâbâZü[âWé╠Åoù═            ;
  787. ;-----------------------------------------------;
  788.     public    mesout                ;
  789. mesout    proc    near                ;
  790.     push    ds                ;
  791.     push    ax                ;
  792.     push    dx                ;
  793.     push    cs                ;
  794.     pop    ds                ;
  795.     call    dispent                ;
  796.     pop    dx                ;
  797.     pop    ax                ;
  798.     pop    ds                ;
  799.     ret                    ;
  800. mesout    endp                    ;
  801.                         ;
  802. ;-----------------------------------------------;
  803. ;    û╪ì\æóé╠ì─ì\Æz                ;
  804. ;-----------------------------------------------;
  805.     public    reconst                ;
  806. reconst    proc    near                ;
  807.     push    si                ;
  808.                         ;
  809.     xor    si, si                ;
  810.     mov    di, si                ;
  811. $_69:
  812.         mov    bx, son[si]        ;
  813.         lodsw                ; freq[si]
  814.         cmp bx, bp
  815.         jB $_71
  816.             inc    ax        ;
  817.             shr    ax, 1        ;
  818.             mov    son[di], bx    ;
  819.             stosw            ; mov    freq[di], ax
  820.                         ; add    di, 2
  821. $_71:
  822.     cmp si, bp
  823.     jB $_69
  824. $_70:
  825.     xor    si, si                ;
  826. $_72:
  827.         push    si            ;
  828.         lodsw                ; freq[si]
  829.         add    ax, [si]        ; freq[bx]
  830.         mov    [di], ax        ; freq[di], ax
  831.                         ;
  832.         mov    bx, di            ;
  833. $_74:
  834.             dec    bx        ;
  835.             dec    bx        ;
  836.         cmp ax, [bx]
  837.         jB $_74
  838. $_75:
  839.         inc    bx            ;
  840.         inc    bx            ;
  841.                         ;
  842.         push    ax            ;
  843.         push    di            ;
  844.         std                ;
  845.         jmp    short rc1        ;
  846. $_76:
  847.             mov    ax, [di - 2]    ; freq[di - 2]
  848.             mov    cx, son[di - 2]    ;
  849.             mov    son[di], cx    ;
  850.             stosw            ; freq[di], ax
  851. rc1:                        ;
  852.         cmp di, bx
  853.         jA $_76
  854. $_77:
  855.         cld                ;
  856.         pop    di            ;
  857.         pop    [bx]            ; freq[bx]
  858.         pop    son[bx]            ;
  859.                         ;
  860.         lodsw                ; add    si, 2
  861.         scasw                ; add    di, 2
  862.     cmp di, bp
  863.     jB $_72
  864. $_73:
  865.     xor    si, si                ;
  866. $_78:
  867.         mov    di, son[si]        ;
  868.         mov    prnt[di], si        ;
  869.         cmp di, bp
  870.         jAE $_80
  871.             mov    prnt[di + 2], si;
  872. $_80:
  873.         lodsw                ; add    si, 2
  874.     cmp si, bp
  875.     jB $_78
  876. $_79:
  877.                         ;
  878.     pop    si                ;
  879.     ret                    ;
  880. reconst    endp                    ;
  881.                         ;
  882. ;-----------------------------------------------;
  883. ;    û╪ì\æóé╠ìXÉV                ;
  884. ;-----------------------------------------------;
  885. ;    si : prnt[c + T]            ;
  886. ;-----------------------------------------------;
  887.     public    update                ;
  888. update    proc    near                ;
  889.     or freq[R * 2], 0
  890.     jNS $_81
  891.         call    near ptr reconst    ;
  892. $_81:
  893.     mov    si, ds:prnt[si + bp]        ;
  894. $_82:
  895.         mov    di, si            ; lea    di, freq[si]
  896.         mov    ax, [di]        ;
  897.         scasw    ; inc    di        ;
  898.             ; inc    di        ;
  899.         scasw
  900.         jNE $_84
  901.             mov    cx, 0ffffh    ; must large enough
  902.             repe    scasw        ;
  903.             sub    di, 4        ; offset freq + 4
  904.                         ;
  905.             mov    bx, son[si]    ;
  906.             mov    prnt[bx], di    ;
  907.             cmp bx, bp
  908.             jAE $_85
  909.                 mov    prnt[bx + 2], di
  910. $_85:
  911.             xchg    bx, son[di]    ;
  912.             mov    prnt[bx], si    ;
  913.             cmp bx, bp
  914.             jAE $_86
  915.                 mov    prnt[bx + 2], si
  916. $_86:
  917.             mov    son[si], bx    ;
  918.                         ;
  919.             mov    si, di        ;
  920. $_84:
  921.         inc    word ptr [si]        ; freq[si]
  922.         mov    si, prnt[si]        ;
  923.     or si, si
  924.     jNZ $_82
  925. $_83:
  926.     ret                    ;
  927. update    endp                    ;
  928.                         ;
  929. ;-----------------------------------------------;
  930. ;    égétéeé╠ë≡ô╟                ;
  931. ;-----------------------------------------------;
  932.         public    DecodeChar        ;
  933. DecodeChar    proc    near            ;
  934.     push    bp                ;
  935.     mov    bp, T * 2            ;
  936.     mov    si, son[R * 2]            ;
  937.     mov    dx, DGROUP:iobuf        ;
  938.     mov    cl, DGROUP:iolen        ;
  939.     xor    ch, ch                ;
  940. $_87:
  941.         jcxz    getword            ;
  942. dc2:                        ;
  943.         shr    si, 1            ;
  944.         shl    dx, 1            ;
  945.         adc    si, 0            ;
  946.         shl    si, 1            ;
  947.         mov    si, son[si]        ;
  948.         dec    cx            ;
  949.     cmp si, bp
  950.     jB $_87
  951. $_88:
  952.     mov    DGROUP:iobuf, dx        ;
  953.     mov    DGROUP:iolen, cl        ;
  954.     sub    si, bp                ;
  955.     push    si                ;
  956.     call    near ptr update            ;
  957.     pop    ax                ;
  958.     shr    ax, 1                ;
  959.     pop    bp                ;
  960.     ret                    ;
  961. DecodeChar    endp                ;
  962.                         ;
  963.     public    getword                ;
  964. getword:                    ;
  965.     call    getc                ;
  966.     mov    dh, al                ;
  967.     call    getc                ;
  968.     mov    dl, al                ;
  969.     mov    cl, 16                ;
  970.     jmp    short dc2            ;
  971.                         ;
  972. ;-----------------------------------------------;
  973. ;    getc                    ;
  974. ;        ax: 1 byte (return)            ;
  975. ;-----------------------------------------------;
  976.     public    getc                ;
  977. getc    proc    near                ;
  978.     cmp inpptr, offset inpbuf + BufSiz
  979.     jB $_89
  980.         call    getbuf            ;
  981. $_89:
  982.     mov    bx, inpptr            ;
  983.     mov    al, [bx]            ;
  984.     inc    inpptr                ;
  985.     xor    ah, ah                ;
  986.     ret                    ;
  987. getc    endp                    ;
  988.                         ;
  989. ;-----------------------------------------------;
  990. ;    ôⁿù═é⌐éτéÄârâbâgé≡ô╛éΘ            ;
  991. ;-----------------------------------------------;
  992. ;    cl : n bits                ;
  993. ;-----------------------------------------------;
  994.         public    GetNBits        ;
  995. GetNBits    proc    near            ;
  996.     push    cx                ;
  997.     mov    dx, DGROUP:iobuf        ;
  998.     cmp iolen, 8
  999.     jG $_90
  1000.         call    getc            ;
  1001.         mov    cl, 8            ;
  1002.         sub    cl, DGROUP:iolen    ;
  1003.         shl    ax, cl            ;
  1004.         or    dx, ax            ;
  1005.         add    DGROUP:iolen, 8        ;
  1006. $_90:
  1007.     pop    cx                ;
  1008.     mov    ax, dx                ;
  1009.     shl    dx, cl                ;
  1010.     mov    DGROUP:iobuf, dx        ;
  1011.     sub    DGROUP:iolen, cl        ;
  1012.     mov    dx, -1                ;
  1013.     shr    dx, cl                ;
  1014.     not    dx                ;
  1015.     and    ax, dx                ;
  1016.     ret                    ;
  1017. GetNBits    endp                ;
  1018.                         ;
  1019. ;-----------------------------------------------;
  1020. ;    ê╩ÆuÅεò±é╠ë≡ô╟                ;
  1021. ;-----------------------------------------------;
  1022.         public    DecodePosition        ;
  1023. DecodePosition    proc    near            ;
  1024.     mov    cx, 8                ;
  1025.     call    near ptr GetNBits        ;
  1026.     xchg    al, ah                ;
  1027.     mov    si, ax                ;
  1028.     mov    dl, d_code[si]            ;
  1029.     mov    dh, 0                ;
  1030.     mov    cl, 6                ;
  1031.     shl    dx, cl                ;
  1032.     push    dx                ;
  1033.     mov    cl, d_len[si]            ; ch == 0
  1034.     call    near ptr GetNBits        ;
  1035.     or    ax, si                ;
  1036.     rol    ax, cl                ;
  1037.     and    ax, 003fh            ;
  1038.     pop    dx                ;
  1039.     add    ax, dx                ;
  1040.     ret                    ;
  1041. DecodePosition    endp                ;
  1042.                         ;
  1043. ;-----------------------------------------------;
  1044. ;    Decode                    ;
  1045. ;-----------------------------------------------;
  1046.     public    Decode                ;
  1047. Decode    proc    near                ;
  1048.     mov    si, offset DGROUP:cpyhdr.OrgSiz    ;
  1049.     lodsw                    ;
  1050.     or    ax, [si]            ;
  1051.     jNZ $_91
  1052.         jmp    de9            ;
  1053. $_91:
  1054.     push    ds                ;
  1055.     pop    es                ;
  1056. ;---------------------------------------    ;
  1057. ;  égétéeùpé╠û╪ì\æóé╠Åëè·ë╗            ;
  1058. ;---------------------------------------    ;
  1059.     public    StartHuff            ;
  1060. StartHuff:                    ;
  1061.     mov    ax, 1                ;
  1062.     mov    cx, N_CHAR            ;
  1063.     push    cx                ;
  1064.     xor    di, di                ; mov    di, offset DGROUP:freq
  1065.     rep    stosw                ;
  1066.     mov    ax, T * 2            ;
  1067.     xor    dx, dx                ;
  1068.     pop    cx                ;
  1069.     mov    di, offset DGROUP:son        ;
  1070.     mov    bx, offset DGROUP:prnt[T * 2]    ;
  1071. $_92:
  1072.         stosw                ;
  1073.         inc    ax            ; add    ax, 2
  1074.         inc    ax            ;
  1075.         mov    [bx], dx        ;
  1076.         inc    bx            ; add    bx, 2
  1077.         inc    bx            ;
  1078.         inc    dx            ; add    dx, 2
  1079.         inc    dx            ;
  1080.     LOOP $_92
  1081. $_93:
  1082.                         ;
  1083.     xor    si, si                ;
  1084.     mov    di, N_CHAR * 2            ;
  1085.     mov    cx, N_CHAR - 1            ;
  1086. $_94:
  1087.         mov    son[di], si        ;
  1088.         mov    prnt[si], di        ;
  1089.         lodsw                ; mov    ax, freq[si]
  1090.         add    ax, [si]        ; add    ax, freq[si + 2]
  1091.         mov    prnt[si], di        ;
  1092.         stosw                ; mov    freq[di], ax
  1093.         lodsw                ;
  1094.     LOOP $_94
  1095. $_95:
  1096.     xor    ax, ax                ;
  1097.     mov    iobuf, ax            ;
  1098. ;    mov    iolen, al            ;
  1099.     mov    DGROUP:prnt[R * 2], ax        ; prnt[R * 2], 0
  1100.     dec    ax                ;
  1101.     mov    [di], ax            ; freq[T * 2], -1
  1102. ;---------------------------------------    ;
  1103.                         ;
  1104.     mov    al, 20h                ;
  1105.     mov    cx, F                ;
  1106.     mov    di, offset DGROUP:text_buf + N - F
  1107.     rep    stosb                ;
  1108.                         ;
  1109.     xor    di, di                ;
  1110.     mov    bp, N - 1            ;
  1111. $_96:
  1112.         push    di            ;
  1113.         call    near ptr DecodeChar    ;
  1114. ;        $_if                ;
  1115.         or    ah, ah            ;
  1116.         jnz    de1            ;
  1117.             pop    di        ;
  1118.             mov    cx, 1        ;
  1119.             push    cx        ;
  1120.             jmp    short de2    ;
  1121. ;        $_else                ;
  1122. de1:                        ;
  1123.             push    ax        ;
  1124.             call    near ptr DecodePosition
  1125.             pop    cx        ;
  1126.             pop    di        ;
  1127.             mov    si, di        ;
  1128.             sub    si, ax        ;
  1129.             dec    si        ;
  1130.             and    si, bp        ;
  1131.             sub    cx, 255 - THRESHOLD
  1132.             push    cx        ;
  1133. $_98:
  1134.                 mov    al, DGROUP:text_buf[si]
  1135.                 inc    si    ;
  1136.                 and    si, bp    ;
  1137. de2:                        ;
  1138.                 mov    DGROUP:text_buf[di], al
  1139.                 inc    di    ;
  1140.                 cmp di, bp
  1141.                 jBE $_100
  1142.                     push    cx
  1143.                     call    putbuf
  1144.                     pop    cx
  1145. $_100:
  1146.                 and    di, bp    ;
  1147.             LOOP $_98
  1148. $_99:
  1149.             pop    cx        ;
  1150. ;        $_elseif            ;
  1151.         mov    bx, offset DGROUP:cpyhdr.OrgSiz
  1152.         sub    [bx], cx        ;
  1153.         pushf                ;
  1154.         sbb    word ptr 2[bx], 0    ;
  1155.         pop    ax            ;
  1156.         lahf                ;
  1157.         and    ah, al            ;
  1158.         sahf                ;
  1159.     jG $_96
  1160. $_97:
  1161.     call    putbuf                ;
  1162. de9:                        ;
  1163.     ret                    ;
  1164. Decode    endp                    ;
  1165.                         ;
  1166. ;-----------------------------------------------;
  1167. ;    is Japanese kanji char            ;
  1168. ;-----------------------------------------------;
  1169.     public    iskanji                ;
  1170. iskanji    proc    near                ;
  1171.     push    ax                ;
  1172.     and    al, 0e0h            ;
  1173.     cmp    al, 080h            ;
  1174.     je    ik_ret                ;
  1175.     cmp    al, 0e0h            ;
  1176. ik_ret:                        ;
  1177.     pop    ax                ;
  1178.     ret                    ;
  1179. iskanji    endp                    ;
  1180.                         ;
  1181. ;-----------------------------------------------;
  1182. ;    is delimiter of path-name        ;
  1183. ;-----------------------------------------------;
  1184.     public    isdelim                ;
  1185.     public    isdelim2            ;
  1186. isdelim proc    near                ;
  1187.     cmp    al, ':'                ;
  1188.     je    id_ret                ;
  1189. isdelim2:                    ;
  1190.     cmp    al, '\'                ;
  1191.     je    id_ret                ;
  1192.     cmp    al, '/'                ;
  1193. id_ret:                        ;
  1194.     ret                    ;
  1195. isdelim endp                    ;
  1196.                         ;
  1197. ;-----------------------------------------------;
  1198. ;    is spacing char                ;
  1199. ;-----------------------------------------------;
  1200.     public    isspace                ;
  1201. isspace proc    near                ;
  1202.     cmp    al, 0dh                ;
  1203.     je    is_ret                ;
  1204.     cmp    al, 09h                ;
  1205.     je    is_ret                ;
  1206.     cmp    al, ' '                ;
  1207. is_ret:                        ;
  1208.     ret                    ;
  1209. isspace endp                    ;
  1210.                         ;
  1211. ;-----------------------------------------------;
  1212. ;    transfer from cmd-line            ;
  1213. ;-----------------------------------------------;
  1214.     public    trans                ;
  1215.     public    trans_t                ;
  1216. trans    proc    near                ;
  1217. $_101:
  1218.         mov    ah, al            ;
  1219.         stosb                ;
  1220.         call iskanji
  1221.         jNZ $_103
  1222.             movsb            ;
  1223. $_103:
  1224. trans_e:                    ;
  1225.         lodsb                ;
  1226. trans_t:                    ;
  1227.     call isspace
  1228.     jNZ $_101
  1229. $_102:
  1230.     mov    byte ptr es:[di], 0        ;
  1231.     ret                    ;
  1232. trans    endp                    ;
  1233.                         ;
  1234. ;-----------------------------------------------;
  1235. ;    display ASCIZ char            ;
  1236. ;-----------------------------------------------;
  1237.     public    disp                ;
  1238. disp    proc    near                ;
  1239. $_104:
  1240.         inc    bx            ;
  1241.         mov    ah, 02h            ;
  1242.         int    21h            ;
  1243. dispent:                    ;
  1244.         mov    dl, [bx]        ;
  1245.     or dl, dl
  1246.     jNZ $_104
  1247. $_105:
  1248.     ret                    ;
  1249. disp    endp                    ;
  1250.                         ;
  1251.     public    endofcode            ;
  1252. endofcode:                    ;
  1253. _TEXT    ends                    ;
  1254.     end    start                ;
  1255.